18. 答案:TensorFlow 池化层
方案
这是我的做法。注意:有不止一种方法得到正确的输出维度,你的答案可能会跟我的有所不同。
def maxpool(input):
ksize = [1, 2, 2, 1]
strides = [1, 2, 2, 1]
padding = 'VALID'
return tf.nn.max_pool(input, ksize, strides, padding)
我想要把输入的 (1, 4, 4, 1)
转变成 (1, 2, 2, 1)
。padding 方法我选择 'VALID'
。我觉得他更容易理解,也得到了我想要的结果。
out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))
替换入值:
out_height = ceil(float(4 - 2 + 1) / float(2)) = ceil(1.5) = 2
out_width = ceil(float(4 - 2 + 1) / float(2)) = ceil(1.5) = 2
深度在池化的时候不变,所以不用担心。